package cn.edu.hpu.action;

import hirondelle.date4j.DateTime;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.hpu.pojo.Group;
import cn.edu.hpu.pojo.Task;
import cn.edu.hpu.service.GroupService;
import cn.edu.hpu.service.TaskService;
import cn.edu.hpu.util.DateUtil;

import com.opensymphony.xwork2.ActionSupport;

public class TaskAction extends ActionSupport{

	private static final long serialVersionUID = 1L;

	private Task task;
	private TaskService taskService;
	private List<Task> tlist;
	private String time;
	private List<Group> glist;
	private GroupService groupService;
	private String gid;
	private String id;
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	public String taskmessage(){
		tlist = taskService.findAll();
		return SUCCESS;
	}
	
	
	public String editTask2() {
		Task task1 = taskService.findById(task.getTid());
		
		task1.setTcontent(task.getTcontent());
		task1.setTcount(task.getTcount());
		task1.setStart(DateUtil.formateTime(task.getStart()));
		task1.setEnd(DateUtil.formateTime(task.getEnd()));
		taskService.update(task1);
		return null;
	}
	
	public String addTaskJson2() {
		DateTime date = new DateTime(DateUtil.formateTime(time));
		task.setStart(date.toString());
		task.setEnd(new DateTime(date.format("YYYY-MM-DD") + " 23:59:59").toString());
		task.setCreatetime(DateUtil.getNow());
		taskService.save(task);
		
		return SUCCESS;
	}
	
	public String newtask1(){
		glist = groupService.findAll();
		return SUCCESS;
	}
	public String addtask1(){
		Group group = groupService.findA(gid);
		taskService.savetask1(task,group);
		return SUCCESS;
	}
	public String taskdelete(){
		taskService.delete(id);
		return SUCCESS;
	}
	public String taskupdate(){
		task = taskService.findById(id);
		return SUCCESS;
	}
	
	//setter,getter
	public Task getTask() {
		return task;
	}
	public void setTask(Task task) {
		this.task = task;
	}
	public TaskService getTaskService() {
		return taskService;
	}
	@Autowired
	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}
	public List<Task> getTlist() {
		return tlist;
	}
	public void setTlist(List<Task> tlist) {
		this.tlist = tlist;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public List<Group> getGlist() {
		return glist;
	}
	public void setGlist(List<Group> glist) {
		this.glist = glist;
	}
	public GroupService getGroupService() {
		return groupService;
	}
	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}
	public String getGid() {
		return gid;
	}
	public void setGid(String gid) {
		this.gid = gid;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
}
